package com.tjbklx1.pattern.flyweight.demo4;

import org.junit.Test;

public class TestApp {

	@Test
	public void test1() {
		// 初始化对象池
		ExtrinsicState state1 = new ExtrinsicState();
		state1.setSubject("科目1");
		state1.setLocation("上海");
		SignInfoFactory.getSignInfo(state1);
		ExtrinsicState state2 = new ExtrinsicState();
		state2.setSubject("科目1");
		state2.setLocation("上海");
		// 计算执行100万次需要的时间
		long currentTime = System.currentTimeMillis();
		for (int i = 0; i < 1000000; i++) {
			SignInfoFactory.getSignInfo(state2);
		}
		long tailTime = System.currentTimeMillis();
		System.out.println("执行时间：" + (tailTime - currentTime) + " ms");

		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Test
	public void test2() {

		String key1 = "科目1上海";
		String key2 = "科目1上海";
		// 初始化对象池
		com.tjbklx1.pattern.flyweight.demo2.SignInfoFactory.getSignInfo(key1);
		// 计算执行10万次需要的时间
		long currentTime = System.currentTimeMillis();
		for (int i = 0; i < 10000000; i++) {
			com.tjbklx1.pattern.flyweight.demo2.SignInfoFactory.getSignInfo(key2);
		}
		long tailTime = System.currentTimeMillis();
		System.out.println("执行时间：" + (tailTime - currentTime) + " ms");

		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
